name = "小明"
age = 18
print(name + "今年" + str(age) + "岁了")
print("name={} age={}".format(name, age))
print(f"name={name} age={age}")

print(1 // 2)
print(2 // 1)
print(2.1 // 2)
print(1 / 2)
a = 2.2
b = 3.3
c = 2
a /= c
b //= c
# 语法错误不能自动转成字符串  print(a + "  " + b)
print(a)
print(b)

print(100 == "100")

a = 300
if a > 300:
    print('先还信用卡的钱')
if a > 400:
    print('又可以happy了~')
else:
    print('噢，no。。。还得等30天！')
    print('缩进默认会被执行')
print('最后：盼着发工资')

age = 100
# 要求人的年龄在 0-120 之间
if age >= 0 and age <= 120:
    print("年龄正确")
else:
    print("年龄不正确")

# 用于记录是否为公司员工的标记
employee = True
# 如果不是提示不允许入内
if not employee:
    print("非公勿内")
print('可以进入')

score = 49
if score >= 90:
    print("优")
elif score >= 80 and score < 90:
    print("良")
elif score >= 70 and score < 80:
    print("中")
elif score >= 30 and score < 70:
    print("差")

# 1. 定义重复次数计数器
i = 1
# 2. 使用 while 判断条件
while i <= 100:
    # 要重复执行的代码
    print("媳妇儿,我错了")
    # 处理计数器 i
    i = i + 1
    vv = 2
print(f"循环结束后的 i = {i}")
print(vv)  # 区域块内定义的变量居然出来后还能引用执行？？？？

str1 = 'itheima'
a = 0
for i in str1:
    a += 1
    if i == 'e':
        print('遇到e停止循环')
        break
print(a)  # 第几次循环遇见e

for i in range(100):
    print(f"媳妇儿,我错了 i={i}")
    break

str1 = "I'm tom"  # 单双引号配合使用
str2 = "I\'m tom"  # 使用转义字符进行转义
print(str1)
print(str2)

# 处理转义字符
file_path1 = "C:\\Desktop\\test"  # 转义
file_path2 = r"C:\Desktop\test"  # 忽略转义字符
file_path3 = "C:\Desktop\test"  # 忽略转义字符
print(file_path1)
print(file_path2)
print(file_path3)

print("12a".find('1'))

data = "黑马程序员"
index = data.find("黑马")
print(f"index={index}")
index2 = data.find("程序")
print(f"index2={index2}")

data = "金三胖同志被称之为世界最成功的80后，金三胖真牛！"
new_data = data.replace("金三胖", "马赛克")
print(data)
print(new_data)

data = ['Python', 'Java', 'PHP']
print(" and ".join(data))  # Python and Java and PHP

data_list = list()
print(data_list)  # []

val_list = ["Web", "UI", "接口"]
val = val_list.pop(0)
print(val, val_list)  # web，['UI', '接口']

val_list = ["Web", "UI", "接口", ]
user_info = (1, 2,)

{
    "name": "xiaoming",
    "age": 28,
    "gender": "男"
}

info = {
    "name": "tom",
    "age": 18
}
info["salary"] = 100000
print(info)
# {'name': 'tom', 'age': 18, 'salary': 100000}

info = {
    "name": "tom",
    "age": 18,
    "gender": "男"
}
info.pop("gender")
print(info)
# {'name': 'tom', 'age': 18}

info = {
    "name": "tom",
    "age": 18,
    "gender": "男"
}
print(info.get("name"))  # tom
print(info.get("abc"))  # None

info = {
    "name": "tom",
    "age": 18,
    "gender": "男"
}
for key in info.keys():
    print(key)  # 循环得到字典中每个键名

info = {
    "name": "tom",
    "age": 18,
    "gender": "男"
}
for k, v in info.items():
    print(f"key={k} value={v}")

name = "abcdefg"
print(name[2:5:1])  # cde
print(name[2:5])  # cde
print(name[:5])  # abcde
print(name[1:])  # bcdefg
print(name[:])  # abcdefg
print(name[::2])  # aceg
print(name[:-1])  # abcdef, 负1表示倒数第一个数据
print(name[-4:-1])  # def
print(name[::-1])  # gfedcba，负1表示倒序
print(name[::8])  # a, 超出步长则只去第一个数据

n = [2, 5, 1, 3][::2]
print(n)  # [2,1]

n = (2, 5, 1, 3)[::2]
print(n)  # (2,1)

a = {
    "a": {"2": 1},
    "b": {"2": 1}
}
print(len(a))

b = ((1, 2), (3, 4, 4))
print(b)


def test(a, b):
    print(a + b)
    # return(a+b)


result = test(1, 2)
print(result)
print(type(result))


def test01():
    print("test01")


def test02():
    print("test02")
    test01()


if __name__ == '__main__':
    test02()


def test(num):
    print(f"{num} 在函数内的内存地址是 {id(num)}")
    result = 100
    print(f"返回值 {result} 在内存中的地址是 {id(result)}")
    return result


a = 10
print(f"调用函数前 内存地址是 {id(a)}")
r = test(a)
print(f"调用函数后 实参内存地址是 {id(a)}")
print(f"调用函数后 返回值内存地址是 {id(r)}")

a = 10
print(id(a))
a = "hello"
print(id(a))
a = "hello" + "666"
print(id(a))

demo_list = [1, 2, 3]
print(f"定义列表后的内存地址 {id(demo_list)}")
demo_list.append(999)
print(f"修改数据后的内存地址 {id(demo_list)}")

demo_dict = {"name": "小明"}
print(f"定义字典后的内存地址 {id(demo_dict)}")
demo_dict["age"] = 18
demo_dict["name"] = "老王"
print(f"修改数据后的内存地址 {id(demo_dict)}")

sum = lambda arg1, arg2: (arg1 + arg1) - (arg2 * arg2)
# 调用sum函数
print("result=", sum(10, 20))  # result= 30
print("result=", sum(20, 20))  # result= 40

info = {
    "name": "tom",
    "age": 18
}
info["s"] = 10
print(info["name"])

user_list = [
    {'name': '张三', 'age': 22, 'title': '测试工程师'},
    {'name': '李四', 'age': 24, 'title': '开发工程师'},
    {'name': '王五', 'age': 21, 'title': '测试工程师'}
]
key = lambda x: x["age"]
print(key)
# 按照age进行排序
user_list.sort(key=lambda x: x["age"])
print(user_list)

user_list = [
    {'name': '张三', 'age': 22, 'title': '测试工程师'},
    {'name': '李四', 'age': 24, 'title': '开发工程师'},
    {'name': '王五', 'age': 21, 'title': '测试工程师'}
]
# 按照age进行排序
user_list.sort(key=lambda x: x["age"])
print(user_list)
# def aa(x):
#     return x["age"]

user_list = [
    {'name': '张三', 'age': 22, 'title': '测试工程师'},
    {'name': '李四', 'age': 24, 'title': '开发工程师'},
    {'name': '王五', 'age': 21, 'title': '测试工程师'}
]
x = '李'
def search(x):
    for y in user_list:
        if y.get('name') == x:
            print('找到了')
            return y
print(search(x) == None)

mystr = 'hellomy'
mystr.startswith('hello')

print('hello'.rpartition('d'))
print('hello'.partition('d'))
